---@class RedRob.StateBase
local StateBase = RedRob.CreateClass("StateBase")
function StateBase:ctor(stateId)
    self.stateId = stateId
    ---@type RedRob.Player
    self.actor = nil
    self.isEnter = false
    self.isFinished = false
    self.delayFinishedTime = -100
    self.nextStateId = 0
    self.isPlaying = false
    self:Init()
end
---@param actor RedRob.Player
function StateBase:BaseEnter(actor,data)
    self.actor = actor
    self.data = data
    if self.isEnter then
        self:BaseReEnter()
        return
    end
    self.delayFinishedTime = -100
    self.isFinished = false
    self.isEnter = true
    self.isPlaying = false
    self:OnEnter()
end
function StateBase:BaseReEnter()
    self:OnReEnter()
end
function StateBase:BaseExit()
    self.actor = nil
    self.data = nil
    self.isEnter = false
    self.isPlaying = false
    self:OnExit()
end
function StateBase:PlayAction(name,isLoop,forcePlay,fixTime)
    if self.isPlaying and not forcePlay then return end
    local anim = self.actor:GetAnimation()
    if anim then
        self.isPlaying = true
        fixTime = fixTime or -1
        local time = Util.PlayAction(anim,name,isLoop,fixTime)
        if not isLoop then
            self:SetDelayFinished(time)
        end
    else
        if not isLoop then --添加保护，未加载资源默认1秒
            self:SetDelayFinished(1)
        end
    end
end
function StateBase:SetDelayFinished(delay)
    self.delayFinishedTime = delay
    self.isFinished = delay < 0 and true or false
end
function StateBase:IsFinished()
    return self.isFinished
end
function StateBase:BaseUpdate(dt)
    if self.delayFinishedTime >= 0 then
        self.delayFinishedTime = self.delayFinishedTime - dt
        if self.delayFinishedTime < 0 then
            self.isFinished = true
        end
    end
    self:Update(dt)
end
function StateBase:GetNextStateId()
    return self.nextStateId
end
function StateBase:SetNextStateId(id)
    self.nextStateId = id
end
--region 子类重写
function StateBase:Init()

end
function StateBase:OnEnter()

end
function StateBase:OnReEnter()
end
function StateBase:OnExit()

end
function StateBase:Update(dt)

end
--endregion 子类重写